<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文</title>
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" />
<script type="text/javascript" th:src="@{/js/jquery.js}"></script>
<script type="text/javascript">
function tipOpen(content,cid) {
    $("input[name=quitCid]").val(cid);
	$(".tipright p").text(content);
	$("#tip").fadeIn(200);
}
function tipClose(num) {
    if(num==1){ // 改变仓库的状态【注销/恢复】  num为1为确定执行
      // 仓库id
      var cid = $("input[name=quitCid]").val();
      // 当前页码
      var pagenum = $(".current a:eq(0)").text();
      // console.log("pagenum:"+pagenum+",cid:"+cid);
      location.href="/erp/storage/changeStatus?cid="+cid+"&pageno="+pagenum;
    }
	$("#tip").fadeOut(200);
}
</script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>仓库管理</li>
    <li>仓库管理</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form th:action="@{/storage/lists}" name="conditionForm" method="post">
    <ul class="tools">
      <li>仓库名称:
        <input type="text" name="cName" th:value="${conditionWare.cName}" />
      </li>
      <li> 所属区域：
        <select name="provinceId" onchange="ajaxProvince(this.value)">
          <option value="">请选择省份</option>
          <option th:each="pv :${session.plist}" th:value="${pv.id}" th:text="${pv.pName}"
                  th:selected="${conditionWare.provinceId==pv.id}" >江苏</option>
        </select>
        <select name="cityId">
          <option th:value="${cityByCid!=null}?${cityByCid.id}" th:text="${cityByCid!=null}?${cityByCid.cName}:'请选择城市'">请选择城市</option>
        </select>
      </li>
      <li class="subBut" onclick="query()"><img th:src="@{/images/t06.png}" />查询</li>
      <li class="subBut" onclick="window.location.href='/erp/storage/toSave'"><img th:src="@{/images/t01.png}" />添加</li>
    </ul>
    <table class="tablelist">
      <thead>
        <tr>
          <th>序号</th>
          <th>仓库名称</th>
          <th>负责人</th>
          <th>联系电话</th>
          <th>所属区域</th>
          <th>状态</th>
          <th>创建时间</th>
          <th>创建人</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>

        <tr th:each="ware,var : ${wPin.list}">
          <td th:text="${(wPin.pageNum-1)*wPin.pageSize+var.count}">1</td>
          <td th:text="${ware.cName}">南京21号仓库</td>
          <td th:text="${ware.usre.uname}">朱元璋</td>
          <td th:text="${ware.phone}">17370899727</td>
          <td th:text="${ware.province.pName}+${ware.city.cName}">江苏南京</td>
          <td th:text="${ware.state=='1'?'可用':'不可用'}">可用</td>
          <td th:text="${#dates.format(ware.creationTime,'yyyy-MM-dd')}">2013-09-09 15:05:05</td>
          <td th:text="${ware.createUser.uname}">马云</td>
          <td>
          	<a th:href="@{/storage/details/?id=}+${ware.id}" class="tablelink">查看详情</a>
            <a th:href="@{/storage/toUdpate?id=}+${ware.id}" class="tablelink">修改</a>
            <a th:text="${ware.state=='1'?'注销':'恢复'}" href="javascript:void(0)" class="tablelink" th:onclick="tipOpen('是否确认[[${ware.state=='1'?'注销':'恢复'}]]此条信息？',[[${ware.id}]])">注销</a>
          </td>
        </tr>

      </tbody>
    </table>
    <div class="pagin">
      <div class="message">共<i class="blue" th:text="${wPin.total}">1256</i>条记录，当前显示第&nbsp;<i class="blue" th:text="${wPin.pageNum}">2&nbsp;</i>页</div>
      <ul class="paginList">
        <li class="paginItem" th:onclick="goPage([[${wPin.pageNum-1}]])"><a href="javascript:;"><span class="pagepre"></span></a></li>
        <li class="paginItem" th:onclick="goPage(1)" th:class="${wPin.pageNum==1?'paginItem current':'paginItem'}"><a href="javascript:;">1</a></li>

        <li th:each="p:${listPage}" th:class="${wPin.pageNum==p?'paginItem current':'paginItem'}" th:onclick="goPage([[${p}]])"><a th:text="${p}" href="javascript:;">2</a></li>

        <li class="paginItem" th:if="${wPin.pages!=1 and wPin.pages!=0}" th:onclick="goPage([[${wPin.pages}]])" th:class="${wPin.pageNum==wPin.pages?'paginItem current':'paginItem'}"><a href="javascript:;" th:text="${wPin.pages}" id="pages" >10</a></li>
        <li class="paginItem"  th:onclick="goPage([[${wPin.pageNum+1}]])"><a href="javascript:;"><span class="pagenxt"></span></a></li>
      </ul>
    </div>
  </form>
  <!-- 提示框 -->
  <div id="tip" class="tip">
    <div class="tiptop"><span>提示信息</span><a onclick="tipClose()"></a></div>
    <div class="tipinfo"> <span><img th:src="@{/images/ticon.png}" /></span>
      <div class="tipright">
        <p></p>
        <cite>如果是请点击确定按钮 ，否则请点取消。</cite> </div>
    </div>
    <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" onclick="tipClose(1)" />
      &nbsp;
      <input name="" type="button"  class="cancel" value="取消" onclick="tipClose()" />
    </div>
    <input name="quitCid" type="hidden">
  </div>
</div>
<script type="text/javascript">

    // 省市级联
    function ajaxProvince(pid){
        $.get("/erp/storage/ajaxProvince",{"pid":pid},function (data) {
            $("select[name=cityId]").html();  // 清空

            var str = "<option value=''>请选择城市</option>";
            $.each(data,function (i,e) {
              str += "<option value="+e.id+" th:selected='${conditionWare.cityId}=="+e.id+"'>"+e.cname+"</option>";
            });
          $("select[name=cityId]").html(str);  // 添加元素

        },"json");
    }

  // 表单提交
  function query(){
    $("form[name='conditionForm']").submit();
  }


  // 页面跳转
    function goPage(num){
      var cName =  $("input[name=cName]").val();
      var provinceId =  $("select[name=provinceId]").val();
      var cityId  = $("select[name=cityId]").val();

      // 最后一页
      var pages = $("#pages").text();
      if(num>=1 && num<=pages){
        location.href="/erp/storage/lists?pageno="+num+"&cName="+cName+"&provinceId="+provinceId+"&cityId="+cityId;
      }
    }

	$('.tablelist tbody tr:odd').addClass('odd');
</script>
</body>
</html>
